<template>
  <div class="axiom-mobile-layout" :data-theme="currentTheme">
    <!-- 顶部头部 - 使用AxiomCard -->
    <AxiomCard class="axiom-mobile-header-card">
      <AxiomGroup direction="horizontal" justify="space-between" align="center">
        <!-- 返回按钮 (二级页面时显示) -->
        <AxiomButton 
          v-if="showBackButton" 
          @click="goBack"
          type="text"
          class="axiom-mobile-back-btn"
        >
          <AxiomIcon name="ArrowLeft" />
        </AxiomButton>
        
        <!-- 页面标题 -->
        <AxiomTitle 
          :title="pageTitle" 
          level="4" 
          type="component"
          class="axiom-mobile-title"
        />
        
        <!-- 筛选按钮 (与顶部合体) -->
        <AxiomButton 
          v-if="showFilterButton" 
          @click="toggleFilter"
          :type="filterActive ? 'primary' : 'text'"
          class="axiom-mobile-filter-btn"
        >
          <AxiomIcon name="Filter" />
        </AxiomButton>
        
        <!-- 占位符，保持布局对称 -->
        <div v-else class="axiom-mobile-placeholder"></div>
      </AxiomGroup>
    </AxiomCard>

    <!-- 主要内容区域 -->
    <AxiomSection class="axiom-mobile-main">
      <router-view />
    </AxiomSection>

    <!-- 底部Tab导航 (一级页面时显示) - 使用AxiomCard -->
    <AxiomCard v-if="showBottomNav" class="axiom-mobile-bottom-nav-card">
      <AxiomGroup direction="horizontal" justify="space-around" align="center">
        <AxiomButton 
          v-for="tab in navigationTabs" 
          :key="tab.name"
          :type="$route.path === tab.path ? 'primary' : 'text'"
          @click="navigateToTab(tab.path)"
          class="axiom-mobile-tab-btn"
        >
          <AxiomGroup direction="vertical" align="center" gap="small">
            <AxiomIcon :name="tab.icon" size="20" />
            <AxiomText 
              :type="$route.path === tab.path ? 'primary' : 'secondary'"
              size="small"
              class="axiom-mobile-tab-label"
            >
              {{ tab.label }}
            </AxiomText>
          </AxiomGroup>
        </AxiomButton>
      </AxiomGroup>
    </AxiomCard>
  </div>
</template>

<script>
import { useThemeStore } from '../../stores/theme';
import AxiomCard from '../common/AxiomCard.vue';
import AxiomGroup from '../common/AxiomGroup.vue';
import AxiomButton from '../common/AxiomButton.vue';
import AxiomTitle from '../common/AxiomTitle.vue';
import AxiomSection from '../common/AxiomSection.vue';
import AxiomText from '../common/AxiomText.vue';
import AxiomIcon from '../common/AxiomIcon.vue';

export default {
  name: 'AxiomMobileLayout',
  components: {
    AxiomCard,
    AxiomGroup,
    AxiomButton,
    AxiomTitle,
    AxiomSection,
    AxiomText,
    AxiomIcon
  },
  props: {
    pageTitle: { type: String, default: 'Axiom UI' },
    showBackButton: { type: Boolean, default: false },
    showFilterButton: { type: Boolean, default: false },
    filterActive: { type: Boolean, default: false },
    customTabs: { type: Array, default: () => [] }
  },
  emits: ['back', 'filter-toggle'],
  data() {
    return {
      defaultTabs: [
        { name: 'home', path: '/', label: '首页', icon: 'HomeFilled' },
        { name: 'components', path: '/components', label: '组件', icon: 'StarFilled' },
        { name: 'examples', path: '/examples', label: '示例', icon: 'CircleCheckFilled' },
        { name: 'settings', path: '/settings', label: '设置', icon: 'Setting' }
      ]
    };
  },
  computed: {
    currentTheme() {
      const themeStore = useThemeStore();
      return themeStore.currentTheme;
    },
    navigationTabs() {
      return this.customTabs.length > 0 ? this.customTabs : this.defaultTabs;
    },
    showBottomNav() {
      // Logic to show bottom nav only on root level paths
      const pathSegments = this.$route.path.split('/').filter(Boolean);
      return pathSegments.length <= 1;
    }
  },
  methods: {
    goBack() {
      if (window.history.length > 1) {
        this.$router.back();
      } else {
        this.$router.push('/');
      }
      this.$emit('back');
    },
    toggleFilter() {
      this.$emit('filter-toggle');
    },
    navigateToTab(path) {
      this.$router.push(path);
    }
  }
}
</script>

<style lang="scss" scoped>
/* Styles copied from MainLayout.vue */
.axiom-mobile-layout {
  height: 100vh;
  width: 100%;
  display: flex;
  flex-direction: column;
  background-color: var(--axiom-bg-color);
}

.axiom-mobile-header-card {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  backdrop-filter: blur(10px);
  border-radius: 0;
  border-bottom: 1px solid var(--axiom-border-color);
  padding: var(--axiom-spacing-sm);
}

.axiom-mobile-title {
  flex: 1;
  text-align: center;
  margin: 0;
}

.axiom-mobile-back-btn,
.axiom-mobile-filter-btn {
  min-width: 40px;
  height: 40px;
  padding: var(--axiom-spacing-xs);
}

.axiom-mobile-placeholder {
  width: 40px;
  height: 40px;
}

.axiom-mobile-main {
  flex: 1;
  margin-top: 80px; /* Adjust based on actual header height */
  margin-bottom: 0;
  overflow-y: auto;
  padding: var(--axiom-spacing-md);
}

.axiom-mobile-layout:has(.axiom-mobile-bottom-nav-card) .axiom-mobile-main {
  margin-bottom: 80px; /* Adjust based on actual footer height */
}

.axiom-mobile-bottom-nav-card {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  backdrop-filter: blur(10px);
  border-radius: 0;
  border-top: 1px solid var(--axiom-border-color);
  padding: var(--axiom-spacing-sm);
}

.axiom-mobile-tab-btn {
  flex: 1;
  min-height: 50px;
  padding: var(--axiom-spacing-xs);
}

.axiom-mobile-tab-label {
  margin: 0;
  line-height: 1;
}

// Responsive adjustments
@media (max-width: 768px) {
  .axiom-mobile-header-card,
  .axiom-mobile-bottom-nav-card {
    padding: var(--axiom-spacing-xs);
  }
  
  .axiom-mobile-main {
    padding: var(--axiom-spacing-sm);
  }
}
</style> 